{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "98bdaaca-627b-4e29-a164-deb1aa8f6e9b",
   "metadata": {},
   "source": [
    "Chapter 08\n",
    "# 自定义抛物线函数，位置参数、关键字参数\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "95600bf9-038d-4c4d-9eac-f3cede28da15",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 位置参数\n",
    "def quadratic_f(a, b, c, x,/):\n",
    "    f = a * x **2 + b * x + c\n",
    "    return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "45f251f8-1f10-4887-837e-8bc14d139db0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f(1, 2, 3, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d92cb1b6-46e0-4eae-8476-b2d599d659df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "57"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f(3, 2, 1, 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ffb56023-be83-4bbb-aa00-3e3c3dd5841e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关键字参数\n",
    "def quadratic_f_2(*, a, b, c, x):\n",
    "    f = a * x **2 + b * x + c\n",
    "    return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "db6353bb-8793-4e18-b681-3f28afe39333",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f_2(a = 1, b = 2, c = 3, x = 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e4a10693-e9fd-4d39-ae99-9928e5fe806c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f_2(c = 3, x = 4, a = 1, b = 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d414a75a-4d9e-49db-bd6c-35ffc7acca17",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关键字/位置参数\n",
    "def quadratic_f_3(a, b, /, c, *, x):\n",
    "    f = a * x **2 + b * x + c\n",
    "    return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "67bacd07-dd28-4423-ba9a-41ff24474e06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f_3(1, 2, 3, x = 4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5dde9322-5ece-4ce7-8045-e59a057195f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "27"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quadratic_f_3(1, 2, c = 3, x = 4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
